//
//  UIImage+extension.m
//  基础框架
//
//  Created by cyanstone on 2016/12/14.
//  Copyright © 2016年 cyanstone. All rights reserved.
//

#import "UIImage+Extension.h"

@implementation UIImage (Extension)

+ (instancetype)imageWithColor:(UIColor *)color {
    
    CGSize size = CGSizeMake(1.f, 1.f);
    
    UIGraphicsBeginImageContext(size);
    
    [color setFill];
    
    UIRectFill((CGRect){CGPointZero,size});
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return image;
    
}

- (instancetype)imageFitWithSize:(CGSize)size {
    
    UIGraphicsBeginImageContextWithOptions(size, YES, 0);
    
    CGRect rect = (CGRect){CGPointZero,size};
    
    [self drawInRect:rect];
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return image;
}

- (instancetype)imageCornerWithRadius:(CGFloat)radius byRoundingCorners:(UIRectCorner)corners fillColor:(UIColor *)fillColor zoomSize:(CGSize)zoomSize {
    
    UIGraphicsBeginImageContextWithOptions(zoomSize, YES, 0);
    
    CGRect rect = (CGRect){CGPointZero,zoomSize};
    
    [fillColor setFill];
    
    UIRectFill(rect);
    
    CGSize size = CGSizeMake(radius, radius);
    
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corners cornerRadii:size];
    
    [path addClip];
    
    [self drawInRect:rect];
    
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    
    return img;
    
}

- (instancetype)imageCornerWithRadius:(CGFloat)radius fillColor:(UIColor *)fillColor zoomSize:(CGSize)zoomSize {
    
    return [self imageCornerWithRadius:radius byRoundingCorners:UIRectCornerAllCorners fillColor:fillColor zoomSize:zoomSize];
}

+ (instancetype)getAppLauchImage{
    
    CGSize viewSize = [UIScreen mainScreen].bounds.size ;
    NSString * viewOrienttation = @"Portrait";
    NSString * launchImage = nil;
    NSArray * imageDict = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"UILaunchImages"];
    for (NSDictionary * dict in imageDict) {
        CGSize imageSize = CGSizeFromString(dict[@"UILaunchImageSize"]);
        if (CGSizeEqualToSize(imageSize, viewSize) && [viewOrienttation isEqualToString:dict[@"UILaunchImageOrientation"]]) {
            launchImage = dict[@"UILaunchImageName"];
        }
    }
    
 
    
    return [UIImage imageNamed:launchImage];
    
}

@end
